/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dabomstew.pkrandom.gui;

import java.util.ResourceBundle;

import com.dabomstew.pkrandom.CodeTweaks;

/**
 * 
 * @author Stewart
 */
public class CodeTweaksDialog extends javax.swing.JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1771633141425200187L;
	private static final ResourceBundle bundle = ResourceBundle
			.getBundle("com/dabomstew/pkrandom/gui/Bundle");
	private boolean pressedOk;

	/**
	 * Creates new form CodeTweaksDialog
	 */
	public CodeTweaksDialog(RandomizerGUI parent, int current, int available) {
		super(parent, true);
		initComponents();
		initialState(available);
		if (current != 0) {
			current &= available;
			restoreFrom(current);
		}
		pressedOk = false;
		setLocationRelativeTo(parent);
		setVisible(true);

	}

	private void initialState(int available) {
		bwPatchCB.setVisible((available & CodeTweaks.BW_EXP_PATCH) > 0);
		nerfXAccCB.setVisible((available & CodeTweaks.NERF_X_ACCURACY) > 0);
		critRateFixCB.setVisible((available & CodeTweaks.FIX_CRIT_RATE) > 0);
	}

	private void restoreFrom(int current) {
		bwPatchCB.setSelected((current & CodeTweaks.BW_EXP_PATCH) > 0);
		nerfXAccCB.setSelected((current & CodeTweaks.NERF_X_ACCURACY) > 0);
		critRateFixCB.setSelected((current & CodeTweaks.FIX_CRIT_RATE) > 0);
	}

	public boolean pressedOK() {
		return pressedOk;
	}

	public int getChoice() {
		int choice = 0;
		if (bwPatchCB.isSelected()) {
			choice |= CodeTweaks.BW_EXP_PATCH;
		}
		if (nerfXAccCB.isSelected()) {
			choice |= CodeTweaks.NERF_X_ACCURACY;
		}
		if (critRateFixCB.isSelected()) {
			choice |= CodeTweaks.FIX_CRIT_RATE;
		}
		return choice;
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        headerLabel = new javax.swing.JLabel();
        bwPatchCB = new javax.swing.JCheckBox();
        nerfXAccCB = new javax.swing.JCheckBox();
        critRateFixCB = new javax.swing.JCheckBox();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("com/dabomstew/pkrandom/gui/Bundle"); // NOI18N
        setTitle(bundle.getString("CodeTweaksDialog.title")); // NOI18N

        headerLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        headerLabel.setText(bundle.getString("CodeTweaksDialog.headerLabel.text")); // NOI18N

        bwPatchCB.setText(bundle.getString("CodeTweaksDialog.bwPatchCB.text")); // NOI18N
        bwPatchCB.setToolTipText(bundle.getString("CodeTweaksDialog.bwPatchCB.toolTipText")); // NOI18N

        nerfXAccCB.setText(bundle.getString("CodeTweaksDialog.nerfXAccCB.text")); // NOI18N
        nerfXAccCB.setToolTipText(bundle.getString("CodeTweaksDialog.nerfXAccCB.toolTipText")); // NOI18N

        critRateFixCB.setText(bundle.getString("CodeTweaksDialog.critRateFixCB.text")); // NOI18N
        critRateFixCB.setToolTipText(bundle.getString("CodeTweaksDialog.critRateFixCB.toolTipText")); // NOI18N

        okButton.setText(bundle.getString("CodeTweaksDialog.okButton.text")); // NOI18N
        okButton.setMaximumSize(new java.awt.Dimension(65, 23));
        okButton.setMinimumSize(new java.awt.Dimension(65, 23));
        okButton.setPreferredSize(new java.awt.Dimension(65, 23));
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText(bundle.getString("CodeTweaksDialog.cancelButton.text")); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cancelButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(critRateFixCB)
                            .addComponent(nerfXAccCB)
                            .addComponent(bwPatchCB)
                            .addComponent(headerLabel))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(headerLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bwPatchCB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(nerfXAccCB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(critRateFixCB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_okButtonActionPerformed
		pressedOk = true;
		setVisible(false);
	}// GEN-LAST:event_okButtonActionPerformed

	private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed
		pressedOk = false;
		setVisible(false);
	}// GEN-LAST:event_cancelButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox bwPatchCB;
    private javax.swing.JButton cancelButton;
    private javax.swing.JCheckBox critRateFixCB;
    private javax.swing.JLabel headerLabel;
    private javax.swing.JCheckBox nerfXAccCB;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables
}
